package cn.wx.pet.service.impl;

import cn.wx.basic.service.impl.BaseServiceImpl;
import cn.wx.pet.domain.Pet;
import cn.wx.pet.domain.PetDetail;
import cn.wx.pet.mapper.PetDetailMapper;
import cn.wx.pet.mapper.PetMapper;
import cn.wx.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PetServiceImpl extends BaseServiceImpl<Pet>  implements IPetService {

    @Autowired
    private PetMapper petMapper;

    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    public void save(Pet pet) {
        //增加t_pet
        petMapper.save(pet);

        //增加t_pet_detail
        PetDetail petDetail = pet.getPetDetail();
        petDetail.setPet_id(pet.getId());
        petDetailMapper.save(petDetail);

    }

    @Override
    public void update(Pet pet) {
        //修改t_pet
        petMapper.update(pet);

        //修改t_pet_detail
        petDetailMapper.update(pet.getPetDetail());
    }

    @Override
    public void remove(Long id) {
        petMapper.remove(id);

        petDetailMapper.remove(id);
    }

    @Override
    public void onSale(List<Long> ids) {
        // 1审核，通过则上架，没通过直接自定义异常，保存一条数据

        // 该状态
        // 上架时间
        Date date = new Date();
        petMapper.onSale(ids,date);
    }

    @Override
    public void offSale(List<Long> ids) {
        /**
         * 改状态 ： sql中写state=1
         * 改下架时间： 创建一个当前时间，数据库修改
         * 1. 对象
         * 2. map
         * 3.直接写两个参数
         */
        Date date = new Date();
        petMapper.offSale(ids,date);

    }
}
